﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoolERP_Entities;
using CoolERP_DAL;

namespace CoolERP_BLL
{
    public class ZL_CPBLL : BaseBLL<ZL_CP>
    {       
        public ZL_CPBLL() { }

        public List<vCP> GetCP(Dictionary<string, string> dc, string orderExpr, int? pageIndex, int pageSize, out int totalCount)
        {
            var predicate = PredicateExtensions.True<vCP>();
            if (dc.Count > 0)
            {
                if (dc.ContainsKey("ID") && !string.IsNullOrEmpty(dc["ID"]))
                {
                    Guid id = new Guid(dc["ID"]);
                    predicate = predicate.AndEx(t => t.ID == id);
                }
                if (dc.ContainsKey("NotID") && !string.IsNullOrEmpty(dc["NotID"]))
                {
                    string[] ids = dc["NotID"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    predicate = predicate.AndEx(t => !ids.Contains(t.ID.ToString()));
                }
                if (dc.ContainsKey("BH") && !string.IsNullOrEmpty(dc["BH"]))
                    predicate = predicate.AndEx(t => t.BH.Contains(dc["BH"]));
                if (dc.ContainsKey("MC") && !string.IsNullOrEmpty(dc["MC"]))
                    predicate = predicate.AndEx(t => t.CPMC.Contains(dc["MC"]));
                if (dc.ContainsKey("CPLX") && !string.IsNullOrEmpty(dc["CPLX"]))
                    predicate = predicate.AndEx(t => t.CPLXBH == dc["CPLX"]);
                if (dc.ContainsKey("CPHXC") && !string.IsNullOrEmpty(dc["CPHXC"]))
                    predicate = predicate.AndEx(t => t.CPMCBH == dc["CPHXC"]);
                if (dc.ContainsKey("CPXBH") && !string.IsNullOrEmpty(dc["CPXBH"]))
                    predicate = predicate.AndEx(t => t.CPXBH == dc["CPXBH"]);
                if (dc.ContainsKey("CPXLBH") && !string.IsNullOrEmpty(dc["CPXLBH"]))
                    predicate = predicate.AndEx(t => t.CPXLBH == dc["CPXLBH"]);
                if (dc.ContainsKey("CPXHBH") && !string.IsNullOrEmpty(dc["CPXHBH"]))
                    predicate = predicate.AndEx(t => t.CPXLBH == dc["CPXHBH"]);
            }

            IZL_CPDAL _dal = new ZL_CPDAL(context);
            return _dal.GetCP(predicate.Compile(), orderExpr, pageIndex, pageSize, out totalCount);
        }

        public List<vCP> GetCP(Func<vCP, bool> exp, string orderExpr, int? pageIndex, int pageSize, out int totalCount)
        {
            IZL_CPDAL _dal = new ZL_CPDAL(context);
            return _dal.GetCP(exp, orderExpr, pageIndex, pageSize, out totalCount);
        }
    }
}
